package com.yanqu.road.server.manger.maidian.shopsroom;

import com.yanqu.road.entity.player.UserBuilding;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.BuildingModule;
import com.yanqu.road.server.manger.DataAnalyticsMgr;
import com.yanqu.road.server.manger.maidian.DefaultEventTraceAction;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ShopsRoomLog {

    public static final String SHOPS_ROOM = "shops_room";
    public static final String SHOPS_CONTENT = "shops_content";

    public static final String SHOPS_NAME = "shops_name";
    public static final String SHOPS_LV = "shops_lv";
    public static final String SHOPS_NUM = "shops_num";
    public static final String SHOPS_ADD = "shops_add";


    public static void uploadSnapshot(GamePlayer player) {

        try {
            if (!DataAnalyticsMgr.openDataAnalytics()) return;

            DefaultEventTraceAction action = new DefaultEventTraceAction(SHOPS_ROOM, player);

            List<Map<String, Object>> objectGroup = new ArrayList<>();
            for (Map.Entry<Integer, UserBuilding> buildingEntry : player.getModule(BuildingModule.class).getBuildingMap().entrySet()) {
                UserBuilding buildingData = buildingEntry.getValue();
                Map<String, Object> map = new HashMap<>();
                map.put(SHOPS_NAME, buildingData.getBuildingId());
                map.put(SHOPS_LV, buildingData.getLevel());
                map.put(SHOPS_NUM, buildingData.getStaffCount());

                //赚钱加成
                map.put(SHOPS_ADD, buildingData.getBuildingEarnSpeed().longValue());
                objectGroup.add(map);
            }
            action.build(SHOPS_CONTENT, objectGroup);

            action.trace();
        } catch (Exception e) {
            DataAnalyticsMgr.getLogger().error(" error ", e);
        }

    }
}
